package o;

import android.content.Context;
import java.io.File;
import java.io.IOException;
import o.fus.a;

public class bjp {
    public static <T extends bje> void ˎ(Context context, fuv o_fuv, bjb o_bjb, bjf<T> o_bjf_T) {
        final bjk o_bjk = new bjk();
        if (!bju.ॱ(context)) {
            ˏ(o_bjk, bju.ˊ(o_bjf_T.getClass()), 0, false, null);
            o_bjf_T.ˋ(o_bjk);
        }
        final String ˎ = o_bjb.ˎ();
        final long ॱ = o_bjb.ॱ();
        final bjf<T> o_bjf_T2 = o_bjf_T;
        o_fuv.ˎ(new a().ˎ(o_bjb.ˊ()).ॱ()).enqueue(new fua() {
            public void onFailure(ftz o_ftz, IOException iOException) {
                bjp.ˏ(o_bjk, bju.ˊ(o_bjf_T2.getClass()), -2, true, iOException);
                o_bjf_T2.ˋ(o_bjk);
            }

            public void onResponse(ftz o_ftz, fvb o_fvb) throws IOException {
                fxg ˋ;
                Exception e;
                Throwable th;
                fxj o_fxj = null;
                int ˊ = o_fvb.ˊ();
                try {
                    ˋ = o_fvb.ᐝ().ˋ();
                    try {
                        o_fxj = fxr.ˋ(fxr.ˏ(bjp.ˏ(ˎ)));
                        fxi ˏ = o_fxj.ˏ();
                        long ˏ2 = o_fvb.ᐝ().ˏ();
                        if (ॱ <= 0 || ˏ2 > ॱ) {
                            bjp.ˏ(o_bjk, bju.ˊ(o_bjf_T2.getClass()), -1, true, null);
                        } else {
                            while (ˋ.ˊ(ˏ, (long) 8192) != -1) {
                                o_fxj.ʼ();
                            }
                            o_fxj.flush();
                            bjp.ˏ(o_bjk, bju.ˊ(o_bjf_T2.getClass()), ˊ);
                        }
                        if (o_fxj != null) {
                            o_fxj.close();
                        }
                        if (ˋ != null) {
                            ˋ.close();
                        }
                        o_bjf_T2.ˋ(o_bjk);
                    } catch (Exception e2) {
                        e = e2;
                        try {
                            bjp.ˏ(o_bjk, bju.ˊ(o_bjf_T2.getClass()), ˊ, true, e);
                            if (o_fxj != null) {
                                o_fxj.close();
                            }
                            if (ˋ != null) {
                                ˋ.close();
                            }
                            o_bjf_T2.ˋ(o_bjk);
                        } catch (Throwable th2) {
                            th = th2;
                            if (o_fxj != null) {
                                o_fxj.close();
                            }
                            if (ˋ != null) {
                                ˋ.close();
                            }
                            o_bjf_T2.ˋ(o_bjk);
                            throw th;
                        }
                    }
                } catch (Exception e3) {
                    e = e3;
                    ˋ = null;
                    bjp.ˏ(o_bjk, bju.ˊ(o_bjf_T2.getClass()), ˊ, true, e);
                    if (o_fxj != null) {
                        o_fxj.close();
                    }
                    if (ˋ != null) {
                        ˋ.close();
                    }
                    o_bjf_T2.ˋ(o_bjk);
                } catch (Throwable th3) {
                    th = th3;
                    ˋ = null;
                    if (o_fxj != null) {
                        o_fxj.close();
                    }
                    if (ˋ != null) {
                        ˋ.close();
                    }
                    o_bjf_T2.ˋ(o_bjk);
                    throw th;
                }
            }
        });
    }

    private static void ˏ(bjk o_bjk, Class cls, int i) {
        o_bjk.ˏ(true);
        o_bjk.ˏ(i);
        o_bjk.ˋ(ˋ(cls));
    }

    private static void ˏ(bjk o_bjk, Class cls, int i, boolean z, Exception exception) {
        o_bjk.ˏ(z);
        o_bjk.ˏ(i);
        o_bjk.ˋ(exception);
        o_bjk.ˋ(ˋ(cls));
    }

    private static File ˏ(String str) {
        File file = new File(str);
        return (file.exists() && file.delete()) ? file : file;
    }

    private static <T> T ˋ(Class<T> cls) {
        try {
            return cls.newInstance();
        } catch (InstantiationException e) {
            return null;
        } catch (IllegalAccessException e2) {
            return null;
        }
    }
}
